<?php
require_once(OC_App::getAppPath('company') . "/lib/quota.php");

if (!PFactory::isMasterUser()) {
   echo '您无权访问该资源';
   exit();
}

$order_id = JRequest::getInt('order_id', 0);

$model = new PCompanyModelQuota();
list($smsList, $pagination) = $model->getSmsHistory();

if (empty($smsList)) {
   echo '<div class="quota_nodata large yahei">短信记录为空</div>';
   exit();
} else {
?>
<div class="ordermenubox">
   <table width="100%" cellpadding="0" cellspacing="0" border="0">
      <tr>
      	 <th width="28%" align="left">姓名</th>
         <th width="32%" align="left">发送内容</th>
         <th width="40%">时间</th>
      </tr>
   </table>  
   
   <table width="100%" cellpadding="0" cellspacing="0" border="0"> 
      <?php foreach ($smsList as $sms): ?>
      <tr>
         <td width="28%"><?=$sms->to_name?></td>
         <td width="32%"><?=$sms->title?></td>
         <td width="40%" align="center"><?=JHtml::_('date', $sms->created, 'Y-m-d H:i')?></td>
      </tr>
      <?php endforeach; ?>
   </table>
</div>

<?php if ($pagination->pagesTotal > 1): ?>
<div id="smsHistoryPagination" style="padding-top:0px;"></div>
<script language="javascript" type="text/javascript">
   jQuery(document).ready(function() {
      jQuery.ajaxSetup({ cache: false });
      jQuery("#smsHistoryPagination").pager({
         pageCount: <?php echo $pagination->pagesTotal; ?>,
         currentPage: <?php echo $pagination->pagesCurrent - 1; ?>
      }).delegate("li.active", "click", function(e) {
         var page = parseInt($(this).attr('page'));
         var url = getUrlQuery("<?=OC_Helper::linkTo('company','ajax/getsmshistory.php')?>", "limitstart=" + (page * <?=$pagination->limit?>));
         var target = jQuery(this);
         jQuery.ajax({
            url: url,
            beforeSend: function(xhr, settings) {
               showLoading(target, settings, null, {button:true});
            },
            success: function(result) {
               jQuery("#smsHistoryBody").html(result);
            }
         })
      }).parent().show();
   })
</script>
<?php endif; ?>

<!-- new pagination, not use for now -->
<?php if (0): ?>
<div class="pagination_own" style="margin-top:10px;">
	 <a href="javascript:;" class="prevpage"><i>&nbsp;</i></a>
   <a href="javascript:;" class="prevpage notclick"><i>&nbsp;</i></a>
   <a href="javascript:;">1</a>
   <a href="javascript:;" class="cur_page">2</a>
   <a href="javascript:;">3</a>
   <a href="javascript:;">4</a>
   ...
   <a href="javascript:;">12</a>
   <a href="javascript:;">13</a>
   <a href="javascript:;">14</a>
   <a href="javascript:;" class="nextpage"><i>&nbsp;</i></a>
   <a href="javascript:;" class="nextpage notclick"><i>&nbsp;</i></a>
</div>
<?php endif; ?>
<?php 
}
?>